package org.dftproject.genesis.ui.pages.summary.details;

import org.dftproject.genesis.data.IAttribute;
import org.dftproject.genesis.data.genealogy.Sex;
import org.dftproject.genesis.ui.SharedImages;
import org.dftproject.genesis.ui.pages.summary.sources.FootnoteContainer;
import org.dftproject.genesis.ui.pages.summary.sources.FootnoteMarker;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.ToolbarLayout;

public class SexFigure extends Figure {

	private final FootnoteContainer footnoteContainer;
	
	private final Label label;
	private FootnoteMarker footnoteMarker;

	public SexFigure(Sex sex, FootnoteContainer footnoteContainer) {
		this.footnoteContainer = footnoteContainer;
		
		ToolbarLayout layout = new ToolbarLayout(true);
		layout.setSpacing(10);
		setLayoutManager(layout);
		
		label = new Label();
		label.setLabelAlignment(PositionConstants.LEFT);
		label.setIconTextGap(5);
		label.setText(sex == Sex.Male ? "Male" : "Female");
		if (sex == Sex.Male)
			label.setIcon(SharedImages.getDefault().getImage(SharedImages.IMG_MALE));
		else if (sex == Sex.Female)
			label.setIcon(SharedImages.getDefault().getImage(SharedImages.IMG_FEMALE));
		add(label);
	}

	public void addSource(IAttribute sourceAttribute) {
		if (footnoteMarker == null) {
			footnoteMarker = new FootnoteMarker(footnoteContainer);
			add(footnoteMarker);
		}
		
		footnoteMarker.addSource(sourceAttribute);
	}

}
